<template>
  <div class="app-container">
    <el-card shadow="never">
    <el-form
      ref="searchForm"
      :inline="true"
      :model="searchMap"
      style="margin-top: 20px;margin-left: 0px"
    >
      <el-form-item prop="devicegateway">
        <el-input v-model="searchMap.devicegateway">
          <template slot="prepend">设备网关</template>
        </el-input>
      </el-form-item>
      <el-button @click="fetchData" icon="el-icon-search"></el-button>
    </el-form>
    <el-button-group style="margin-bottom:20px">
      <el-button type="primary" icon="el-icon-plus"></el-button>
      <el-button type="primary" icon="el-icon-edit"></el-button>
      <el-button type="primary" icon="el-icon-delete"></el-button>
    </el-button-group>

    <!-- 数据列表
    :data 绑定渲染的数据
    border 表格边框
    -->
    <el-table
      border
      :data="list"
      style="width: 100%"
      highlight-current-row
      @current-change="handleSelectionChange"
      @row-click="chooseone"
    >
      <el-table-column width="55">
        <template slot-scope="scope">
          <el-radio v-model="radio" :label="scope.row.id">
            <span class="el-radio__label"></span>
          </el-radio>
        </template>
      </el-table-column>
      <!-- type="index"获取索引值，labal显示标题，prop 数据字段名 -->
      <el-table-column align="center" prop="gatewayname" label="网关名称"></el-table-column>
      <el-table-column align="center" prop="gatewaynum" label="网关编号"></el-table-column>
      <el-table-column align="center" prop="gatewayip" label="网关ip"></el-table-column>
      <el-table-column align="center" prop="gatewayport" label="网关端口"></el-table-column>
      <el-table-column align="center" prop="gatewaystatus" label="网关状态">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="changepassword(scope.row.id)">已关闭</el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="remarks" label="备注"></el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    <template slot="footer"></template>

    <template slot="footer"></template>
    </el-card>
  </div>
</template>


<script>
import systemApi from "@/api/system";
export default {
  data() {
    return {
      total: 0, //总记录数
      list: [],
      currentPage: 1, //当前页码
      pageSize: 10, // 每页显示10条数据
      searchMap: {
        devicegateway: ""
      },
      radio: null, // 如果使用单选框，定义一个model值
      currentSelectItem: {} //当前选中的值
    };
  },

  created() {
    // 初始化获取列表数据
    // this.fetchData();
  },

  methods: {
    // 当每页显示条数改变后，被触发，val是最新的显示条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.fetchData();
    },
    // 当页码改变后，被触发，val是最新的页码
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.fetchData();
    },
    changepassword(id) {
      console.log("重置密码", id);
    },
    // 查询账户信息
    fetchData() {
      // 调用分页查询
      systemApi
        .searchGatewayList(this.currentPage, this.pageSize)
        .then(response => {
          const resp = response.data;
          this.list = resp.data.rows;
          this.total = resp.data.total;
          // console.log(resp);
          // console.log(this.list);
        });
    },
    handleSelectionChange(row) {
      console.log(row);
      this.currentSelectItem = row;
    },
    chooseone(row) {
      this.radio = row.id;
    }
  }
};
</script>